package com.pointcircle.core.web;

import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import com.pointcircle.core.UserContext;
import com.pointcircle.core.web.auth.AuthUtils;

@Component
public class WebUserContext implements UserContext {

	@Override
	public String getUsername() {
		RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
		if(requestAttributes == null) {
			return "AUTO";
		} else {
			if(AuthUtils.getUser() == null) {
				return "UNAUTH_USER";
			} else {
				return AuthUtils.getUser().getUsername();
			}
		}
	}
}
